home *** CD-ROM | disk | FTP | other *** search
- /* Scheme In One Define.
-
- The garbage collector, the name and other parts of this program are
-
- * COPYRIGHT (c) 1989 BY *
- * PARADIGM ASSOCIATES INCORPORATED, CAMBRIDGE, MASSACHUSETTS. *
-
- Conversion to full scheme standard, characters, vectors, ports, complex &
- rational numbers, and other major enhancments by
-
- * Scaglione Ermanno, v. Pirinoli 16 IMPERIA P.M. 18100 ITALY *
-
- Permission to use, copy, modify, distribute and sell this software and its
- documentation for any purpose and without fee is hereby granted, provided
- that the above copyright notice appear in all copies and that both that
- copyright notice and this permission notice appear in supporting
- documentation, and that the name of Paradigm Associates Inc not be used in
- advertising or publicity pertaining to distribution of the software without
- specific, written prior permission.
-
- PARADIGM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- PARADIGM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
- IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <setjmp.h>
- #include <signal.h>
- #include <math.h>
-
- #include "siod.h"
-
- LISP vectorcons(long length,LISP init)
- {long flag,i;
- LISP s,f,*t;
- t=NULL;
- flag = no_interrupt(1);
- if(length>0)
- t = (LISP *)must_malloc(length * sizeof(LISP));
- NEWCELL(s,tc_vector);
- VECTOR(s) = t;
- VECSIZE(s) = length;
- for(i=0;i<length;i++)
- VECTOR(s)[i] = init;
- no_interrupt(flag);
- return(s);}
-
- LISP listtovector(LISP lis)
- {LISP res,l;
- unsigned int n;
- l=lis;
- if(NCONSP(lis)&&NNULLP(lis)) err("list->vector",lis,ERR_GEN_ARG | ERR_NPAI);
- for(n=0;CONSP(l);n++)
- l=cdr(l);
- res = vectorcons(n,NIL);
- l=lis;
- for(n=0;CONSP(l);n++)
- {VECTOR(res)[n] = car(l);
- l=cdr(l);}
- return(res);}
-
- LISP vectortolist(LISP vec)
- {LISP res;
- int n;
- if(NVECTORP(vec)) err("vector->list",vec,ERR_GEN_ARG | ERR_NVEC);
- res= NIL;
- for(n = (VECSIZE(vec))-1;n>=0;n--)
- res = cons(VECTOR(vec)[n],res);
- return(res);}
-
- LISP vectorm(LISP args)
- {LISP res;
- return(listtovector(args));}
-
- LISP makevector(LISP size,LISP init)
- {LISP vec;
- if(NINTNUMP(size)) err("make-vector",size,ERR_FIRST | ERR_NINT);
- vec = vectorcons(INTNM(size),init);
- return(vec);}
-
- LISP vectorset(LISP vec,LISP index,LISP value)
- {if(NVECTORP(vec)) err("vector-set!",vec,ERR_FIRST | ERR_NVEC);
- if(NINTNUMP(index)) err("vector-set!",index,ERR_SECOND | ERR_NINT);
- if((INTNM(index) < 0) || (INTNM(index)+1) > VECSIZE(vec))
- err("vector-set!",index,ERR_SECOND | ERR_IND_RAN);
- VECTOR(vec)[INTNM(index)] = value;
- return(vec);}
-
- LISP vectorfill(LISP vec,LISP value)
- {int i,size;
- if(NVECTORP(vec)) err("vector-fill!",vec,ERR_FIRST | ERR_NVEC);
- size = VECSIZE(vec);
- for(i=0;i<size;i++)
- VECTOR(vec)[i] = value;
- return(vec);}
-
- LISP vectorref(LISP vec,LISP index)
- {if(NVECTORP(vec)) err("vector-ref",vec,ERR_FIRST | ERR_NVEC);
- if(NINTNUMP(index)) err("vector-ref",index,ERR_SECOND | ERR_NINT);
- if((INTNM(index) < 0) || (INTNM(index)+1) > VECSIZE(vec))
- err("vector-ref",index,ERR_SECOND | ERR_IND_RAN);
- return(VECTOR(vec)[INTNM(index)]);}
-
- LISP vectorlenght(LISP vec)
- {LISP res;
- if(NVECTORP(vec)) err("vector-length",vec,ERR_GEN_ARG | ERR_NVEC);
- res=intcons(VECSIZE(vec));
- return(res);}
-
- LISP vectorp(LISP vec)
- {if(VECTORP(vec))
- return(truth);
- else
- return(NIL);}
-